package com.bawei.router

import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.callback.NavigationCallback
import com.bawei.base.RoutePath

/**
 * Author: Jason Zhang
 * Date: 2024/8/21
 * Desc: 局部跳转的降级策略
 */

class LocalDegradeService constructor(private val path: String = "", private val group: String = "") : NavigationCallback {

    private var defaultGroup: String = RoutePath.GROUP_EMPTY
    private var defaultPath: String = RoutePath.PATH_EMPTY_PAGE

    /**
     * 匹配到目标页面
     */
    override fun onFound(postcard: Postcard?) {

    }

    /**
     * 没有匹配到目标页面
     */
    override fun onLost(postcard: Postcard) {
        if (!path.isNullOrEmpty()){
            defaultPath = path
        }

        if (!group.isNullOrEmpty()){
            defaultGroup = group
        }

        postcard.group = defaultGroup
        postcard.path = defaultPath
        postcard.navigation()
    }

    /**
     *  页面跳转成功
     */
    override fun onArrival(postcard: Postcard?) {

    }

    /**
     * 页面跳转被拦截
     */
    override fun onInterrupt(postcard: Postcard?) {

    }


}